const puppeteer = require("puppeteer")
var evaluate = async ctx=>{
    var {id} = ctx.request.params
    const browser = await puppeteer.launch({
        headless:false,
        defaultViewport:null
    });
    const page = await browser.newPage()
    // 123692817
    await page.goto(`https://www.duitang.com/p/atlas/?id=${id}`)
    await page.waitForTimeout(3000)
    var res = await page.evaluate(()=>{
        var $ = window.jQuery
        var arr = []
        var items = $(".cmt-list .cmt")
        items.each((index,value)=>{
            var avatar = $(value).find(".sender-avatar img").attr("src")
            var username = $(value).find(".cmt-r-name").html()
            var time = $(value).find(".cmt-r-time").html()
            var eval_text = $(value).find(".cmt-maincont").text()
            arr.push({
                avatar,
                username,
                time,
                eval_text
            })
        })
        return arr
    })
    await browser.close();
    ctx.body = res
}
module.exports = evaluate